home *** CD-ROM | disk | FTP | other *** search
- From: wht@n4hgf.Mt-Park.GA.US
- Newsgroups: comp.sources.misc
- Subject: v16i073: ECU 3 log-to-Excel spreadsheet, Part02/02
- Message-ID: <1991Jan12.210241.14311@sparky.IMD.Sterling.COM>
- Date: 12 Jan 91 21:02:41 GMT
- Approved: kent@sparky.imd.sterling.com
- X-Checksum-Snefru: b2b31cc2 853564b9 20ff7214 5e7b12a6
-
- Submitted-by: wht@n4hgf.Mt-Park.GA.US
- Posting-number: Volume 16, Issue 73
- Archive-name: ecu3-excel/part02
-
- #!/bin/sh
- # This is part 02 of ecu3-excel
- # ============= excel/ecuxls.c ==============
- if test ! -d 'excel'; then
- echo 'x - creating directory excel'
- mkdir 'excel'
- fi
- if test -f 'excel/ecuxls.c' -a X"$1" != X"-c"; then
- echo 'x - skipping excel/ecuxls.c (File already exists)'
- else
- echo 'x - extracting excel/ecuxls.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'excel/ecuxls.c' &&
- X/* CHK=0x149E */
- Xchar *revision = "1.00";
- X/*+-------------------------------------------------------------------------
- X ecuxls.c - place ECU log info in Excel spreadsheets
- X wht@n4hgf.Mt-Park.GA.US
- X
- X Defined functions:
- X ce_list_add(tce)
- X ce_list_remove(tce)
- X ce_list_search(pid)
- X get_home_dir(home_dir)
- X log_connect(logbuf)
- X log_disconnect(x,logbuf)
- X log_receive(x,logbuf)
- X main(argc,argv)
- X make_brFONT(name,height,attr)
- X make_brFORMAT(picture)
- X make_brLABEL(str)
- X make_brNAME_area(name,firstrow,firstcol,rows,cols)
- X make_brNAME_cell(name,row,col)
- X rearranged_date(date)
- X strlwr(str)
- X xls_append(filename)
- X xls_create_Clog(filename)
- X xls_create_Rlog(filename)
- X xls_get_brDIMENSION(x,dimension)
- X xls_now(now)
- X xls_write_Clog_record(x,row,date,sys,phone,secs)
- X xls_write_Rlog_record(x,row,date,from,length,name)
- X xls_write_br(x,bhdr)
- X xls_write_eof_and_close(x)
- X
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:01-01-1990-16:19-wht@n4hgf-creation */
- X
- X#include <stdio.h>
- X#ifdef NULL
- X#undef NULL
- X#endif
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <ctype.h>
- X#include <errno.h>
- X#include <fcntl.h>
- X#include <malloc.h>
- X#include <memory.h>
- X#include <signal.h>
- X#include <string.h>
- X#include <time.h>
- X#include <pwd.h>
- X
- X#include "biff.h"
- X
- Xlong atol();
- X
- Xtypedef struct xls_file
- X{
- X char filename[128];
- X FILE *fp;
- X long dimension_fpos;
- X int first_data_row;
- X int last_data_row;
- X} XLS_FILE;
- X
- Xtypedef struct ce /* connection linked list entry */
- X{
- X struct ce *prev;
- X struct ce *next; /* we don't need double links, but logic was handy */
- X int pid; /* ecu pid for a connection */
- X char sys[32]; /* system connected to */
- X char date[32];
- X} CE;
- X
- X#if defined(__STDC__)
- Xvoid ce_list_add(struct ce *);
- Xvoid ce_list_remove(struct ce *);
- Xstruct ce *ce_list_search(int);
- Xint get_home_dir(char *);
- Xvoid strlwr(char *);
- Xdouble xls_now(long);
- Xstruct brLABEL *make_brLABEL(char *);
- Xstruct brFONT *make_brFONT(char *,int,int);
- Xstruct brFORMAT *make_brFORMAT(char *);
- Xstruct brNAME *make_brNAME_cell(char *,int,int);
- Xstruct brNAME *make_brNAME_area(char *,int,int,int,int);
- Xlong xls_write_br(struct xls_file *,struct bhdr *);
- Xlong xls_get_brDIMENSION(struct xls_file *,struct brDIMENSION *);
- Xstruct xls_file *xls_append(char *);
- Xstruct xls_file *xls_create_Rlog(char *);
- Xlong xls_write_Rlog_record(struct xls_file *,int,char *,char *,long,char *);
- Xstruct xls_file *xls_create_Clog(char *);
- Xlong xls_write_Clog_record(struct xls_file *,int,char *,char *,char *,long);
- Xvoid xls_write_eof_and_close(struct xls_file *);
- Xchar *rearranged_date(char *);
- Xvoid log_connect(char *);
- Xint log_disconnect(struct xls_file *,char *);
- Xvoid log_receive(struct xls_file *,char *);
- Xint main(int,char **);
- X#else
- Xvoid ce_list_add();
- Xvoid ce_list_remove();
- Xstruct ce *ce_list_search();
- Xint get_home_dir();
- Xvoid strlwr();
- Xdouble xls_now();
- Xstruct brLABEL *make_brLABEL();
- Xstruct brFONT *make_brFONT();
- Xstruct brFORMAT *make_brFORMAT();
- Xstruct brNAME *make_brNAME_cell();
- Xstruct brNAME *make_brNAME_area();
- Xlong xls_write_br();
- Xlong xls_get_brDIMENSION();
- Xstruct xls_file *xls_append();
- Xstruct xls_file *xls_create_Rlog();
- Xlong xls_write_Rlog_record();
- Xstruct xls_file *xls_create_Clog();
- Xlong xls_write_Clog_record();
- Xvoid xls_write_eof_and_close();
- Xchar *rearranged_date();
- Xvoid log_connect();
- Xint log_disconnect();
- Xvoid log_receive();
- X#endif
- X
- X#define HEADER_ROW 0
- X#define HEADER_COL 0
- X
- X#define LABEL_ROW 1
- X#define Rlog_DATE_COL 0
- X#define Rlog_FROM_COL 1
- X#define Rlog_LENGTH_COL 2
- X#define Rlog_NAME_COL 3
- X
- X#define Clog_DATE_COL 0
- X#define Clog_SYS_COL 1
- X#define Clog_PHONE_COL 2
- X#define Clog_TIME_COL 3
- X
- X#define TOTAL_DATA_ROWS 4000
- X
- X#define FONT_HELV10 0
- X#define FONT_HELV10_BOLD 1
- X
- X#define FORMAT_GENERAL 0
- X#define Rlog_FORMAT_DATE 1
- X#define Clog_FORMAT_TIME 1
- X#define FORMAT_COUNT 1 /* do not count "General" */
- X
- XCE *ce_list_head = (CE *)0;
- X
- X/*+-------------------------------------------------------------------------
- X ce_list_add(tce) -- add to linked list
- X--------------------------------------------------------------------------*/
- Xvoid
- Xce_list_add(tce)
- XCE *tce;
- X{
- Xregister CE *this = tce;
- Xregister CE *prev;
- Xregister CE *next;
- X
- X/* if empty, init list with this one and quit */
- X if(ce_list_head == (CE *)0)
- X {
- X ce_list_head = this;
- X this->prev = (CE *)0;
- X this->next = (CE *)0;
- X return;
- X }
- X
- X/* list not empty */
- X prev = (CE *)0; /* no previous yet */
- X next = ce_list_head; /* init next to top of list */
- X
- X while(next->pid < this->pid)
- X {
- X prev = next;
- X next = prev->next;
- X if(next == (CE *)0)
- X break;
- X }
- X
- X if(prev) /* if non-zero, we will not update the list head */
- X {
- X this->next = prev->next;
- X this->prev = prev;
- X prev->next = this;
- X if(next)
- X next->prev = this;
- X }
- X else /* 'this' is to become the new list head (1st element) */
- X {
- X this->next = next;
- X this->prev = (CE *)0;
- X if(next)
- X next->prev = this;
- X ce_list_head = this;
- X }
- X
- X} /* end of ce_list_add */
- X
- X/*+-------------------------------------------------------------------------
- X ce_list_remove(tce) -- remove from linked list
- X--------------------------------------------------------------------------*/
- Xvoid
- Xce_list_remove(tce)
- Xregister CE *tce;
- X{
- Xregister CE *prev;
- Xregister CE *next;
- X
- X prev = (CE *)0; /* there is no previous now */
- X
- X if((next = ce_list_head) == (CE *)0) /* if empty list */
- X return;
- X
- X while(next != tce)
- X {
- X prev = next;
- X next = prev->next;
- X if(next == (CE *)0)
- X return;
- X }
- X
- X/* unlink */
- X if(prev) /* if non-zero, we will not update the list head */
- X {
- X prev->next = tce->next;
- X if(tce->next)
- X (tce->next)->prev = prev;
- X }
- X else
- X {
- X ce_list_head = tce->next;
- X if(tce->next)
- X (tce->next)->prev = (CE *)0;
- X }
- X
- X tce->next = (CE *)0;
- X tce->prev = (CE *)0;
- X
- X} /* end of ce_list_remove */
- X
- X/*+-----------------------------------------------------------------------
- X CE *ce_list_search(pid)
- X------------------------------------------------------------------------*/
- XCE *
- Xce_list_search(pid)
- Xint pid;
- X{
- Xregister CE *tce;
- X
- X tce = ce_list_head;
- X while(tce)
- X {
- X if(tce->pid == pid)
- X return(tce);
- X tce = tce->next;
- X }
- X return(tce);
- X
- X} /* end of ce_list_search */
- X
- X/*+-----------------------------------------------------------------------
- X get_home_dir(home_dir): leave plenty of room for result!
- X------------------------------------------------------------------------*/
- Xint
- Xget_home_dir(home_dir)
- Xchar *home_dir;
- X{
- Xstatic char home_directory[256] = "";
- Xstruct passwd *pwent;
- Xstruct passwd *getpwuid();
- X
- X if(home_directory[0])
- X {
- X strcpy(home_dir,home_directory);
- X return(0);
- X }
- X
- X if(!(pwent = getpwuid(getuid())))
- X {
- X perror("cannot get password entry for you!!");
- X exit(255);
- X }
- X strcpy(home_directory,pwent->pw_dir);
- X strcpy(home_dir,pwent->pw_dir);
- X endpwent();
- X return(0);
- X
- X} /* end of get_home_dir */
- X
- X/*+-------------------------------------------------------------------------
- X strlwr(str) - make all alpha chars in string lower case
- X--------------------------------------------------------------------------*/
- Xvoid
- Xstrlwr(str)
- Xregister char *str;
- X{
- X while(*str)
- X {
- X if(isupper(*str))
- X *str = tolower(*str);
- X str++;
- X }
- X
- X} /* end of strlwr */
- X
- X/*+-------------------------------------------------------------------------
- X xls_now(now) - get time of day in local STANDARD time in XLS units
- X--------------------------------------------------------------------------*/
- Xdouble
- Xxls_now(now)
- Xtime_t now;
- X{
- Xdouble xlsNow;
- X
- X#define EPOCH_DATE 25569 /* 1/1/70 Midnight in XLS units */
- X
- X tzset();
- X now -= timezone;
- X xlsNow = (double)EPOCH_DATE + ((double)now / (double)86400.0);
- X return(xlsNow);
- X
- X} /* end of xls_now */
- X
- X/*+-------------------------------------------------------------------------
- X make_brLABEL(str) - convert null terminated string to brLABEL
- Xcaller needs to plug rw, col and rgbAttr (they all contain 0 at return,
- Xexcept rgbAttr[0], which has rgbAttr0_fLocked set)
- X--------------------------------------------------------------------------*/
- XbrLABEL *
- Xmake_brLABEL(str)
- Xchar *str;
- X{
- Xregister int len = strlen(str);
- Xregister brLABEL *br = (brLABEL *)calloc(1,sizeof(brLABEL) + len - 1);
- X
- X if(!br)
- X {
- X fprintf(stderr,"make_brLABEL: could not get memory for '%s'\n",str);
- X return(br);
- X }
- X
- X br->type = btLABEL;
- X br->length = sizeof(brLABEL) - sizeof(BHDR) + len - 1;
- X br->cch = len;
- X br->rgbAttr[0] = rgbAttr0_fLocked;
- X memcpy((char *)br->rgch,str,(unsigned)len);
- X return(br);
- X
- X} /* end of make_brLABEL */
- X
- X/*+-------------------------------------------------------------------------
- X make_brFONT(name,height,attr)
- X--------------------------------------------------------------------------*/
- XbrFONT *
- Xmake_brFONT(name,height,attr)
- Xchar *name;
- Xint height;
- Xint attr;
- X{
- Xregister int len = strlen(name);
- Xregister brFONT *br = (brFONT *)calloc(1,sizeof(brFONT) + len - 1);
- X
- X if(!br)
- X {
- X fprintf(stderr,"make_brFONT: could not get memory for '%s'\n",name);
- X return(br);
- X }
- X
- X br->type = btFONT;
- X br->length = sizeof(brFONT) - sizeof(BHDR) + len - 1;
- X br->dy = (UINT16)height;
- X br->grbit = (UINT16)attr;
- X br->cch = len;
- X memcpy((char *)br->rgch,name,(unsigned)len);
- X return(br);
- X
- X} /* end of make_brFONT */
- X
- X/*+-------------------------------------------------------------------------
- X make_brFORMAT(picture) - convert null terminated picture to brFORMAT
- X--------------------------------------------------------------------------*/
- XbrFORMAT *
- Xmake_brFORMAT(picture)
- Xchar *picture;
- X{
- Xregister int len = strlen(picture);
- Xregister brFORMAT *br = (brFORMAT *)calloc(1,sizeof(brFORMAT) + len - 1);
- X
- X if(!br)
- X {
- X fprintf(stderr,"make_brFORMAT: could not get memory for '%s'\n",
- X picture);
- X return(br);
- X }
- X
- X br->type = btFORMAT;
- X br->length = sizeof(brFORMAT) - sizeof(BHDR) + len - 1;
- X br->cch = len;
- X memcpy((char *)br->rgch,picture,(unsigned)len);
- X return(br);
- X
- X} /* end of make_brFORMAT */
- X
- X/*+-------------------------------------------------------------------------
- X make_brNAME_cell(name,row,col)
- X--------------------------------------------------------------------------*/
- XbrNAME *
- Xmake_brNAME_cell(name,row,col)
- Xchar *name;
- Xint row;
- Xint col;
- X{
- Xregister int len = strlen(name);
- XopRefN *op;
- Xint len2 = sizeof(brNAME)-1+len + sizeof(*op) + 1;
- Xregister brNAME *br = (brNAME *)calloc(1,len2);
- X
- X if(!br)
- X {
- X fprintf(stderr,"make_brNAME: could not get memory for '%s'\n",name);
- X return(br);
- X }
- X
- X br->type = btNAME;
- X br->length = len2 - sizeof(BHDR);
- X br->cch = (UINT8)len;
- X br->cce = (UINT8)sizeof(opRefN);
- X memcpy((char *)br->rgch,name,(unsigned)len);
- X op = (opRefN *)((char *)(br + 1) + len - 1);
- X op->op = ptgRefN;
- X op->grbitRw = (UINT16)row & 0x3FFF;
- X op->col = (UINT8)col;
- X *((char *)(op + 1)) = br->cce;
- X return(br);
- X
- X} /* end of make_brNAME_cell */
- X
- X/*+-------------------------------------------------------------------------
- X make_brNAME_area(name,firstrow,firstcol,rows,cols)
- X--------------------------------------------------------------------------*/
- XbrNAME *
- Xmake_brNAME_area(name,firstrow,firstcol,rows,cols)
- Xchar *name;
- Xint firstrow;
- Xint firstcol;
- Xint rows;
- Xint cols;
- X{
- Xregister int len = strlen(name);
- XopAreaN *op;
- Xint len2 = sizeof(brNAME)-1+len + sizeof(*op) + 1;
- Xregister brNAME *br = (brNAME *)calloc(1,len2);
- X
- X if(!br)
- X {
- X fprintf(stderr,"make_brNAME: could not get memory for '%s'\n",name);
- X return(br);
- X }
- X
- X br->type = btNAME;
- X br->length = len2 - sizeof(BHDR);
- X br->cch = (UINT8)len;
- X br->cce = (UINT8)sizeof(opAreaN);
- X memcpy((char *)br->rgch,name,(unsigned)len);
- X op = (opAreaN *)((char *)(br + 1) + len - 1);
- X op->op = ptgAreaN;
- X op->grbitRwFirst = (UINT16)firstrow & 0x3FFF;
- X op->grbitRwLast = (op->grbitRwFirst + rows - 1) & 0x3FFF;
- X op->colFirst = (UINT8)firstcol;
- X op->colLast = (UINT8)firstcol + cols - 1;
- X *((char *)(op + 1)) = br->cce;
- X return(br);
- X
- X} /* end of make_brNAME_area */
- X
- X/*+-------------------------------------------------------------------------
- X xls_write_br(x,bhdr)
- X--------------------------------------------------------------------------*/
- Xlong
- Xxls_write_br(x,bhdr)
- XXLS_FILE *x;
- Xregister BHDR *bhdr;
- X{
- Xregister int len = bhdr->length + sizeof(BHDR);
- Xlong fpos = ftell(x->fp);
- X
- X if(fwrite((char *)bhdr,1,len,x->fp) != len)
- X {
- X fprintf(stderr,"xls_write_br type=%d len=%d ",bhdr->type,len);
- X perror(x->filename);
- X return(-1);
- X }
- X return(fpos);
- X
- X} /* end of xls_write_br */
- X
- X/*+-------------------------------------------------------------------------
- X xls_get_brDIMENSION(x,handler)
- X--------------------------------------------------------------------------*/
- Xlong
- Xxls_get_brDIMENSION(x,dimension)
- XXLS_FILE *x;
- XbrDIMENSION *dimension;
- X{
- Xlong fpos;
- XUINT8 buf[2080];
- XBHDR *bhdr = (BHDR *)buf;
- X
- X fseek(x->fp,0L,SEEK_SET);
- X do
- X {
- X fpos = ftell(x->fp);
- X if(fread((char *)buf,1,sizeof(BHDR),x->fp) != sizeof(BHDR))
- X {
- X fprintf(stderr,"xls get dimension short read 1\n");
- X return(-1);
- X }
- X if(fread((char *)buf + sizeof(BHDR),1,(size_t)bhdr->length,x->fp) !=
- X (size_t)bhdr->length)
- X {
- X fprintf(stderr,"xls get dimension short read 2\n");
- X return(-1);
- X }
- X if((bhdr->type == btDIMENSION) &&
- X (bhdr->length == (sizeof(brDIMENSION) - sizeof(BHDR))))
- X {
- X memcpy((char *)dimension,(char *)bhdr,sizeof(brDIMENSION));
- X return(fpos);
- X }
- X } while(bhdr->type != btEOF);
- X
- X fprintf(stderr,"xls get dimension found none to get\n");
- X return(-1);
- X
- X} /* end of xls_get_brDIMENSION */
- X
- X/*+-------------------------------------------------------------------------
- X xls_append(filename)
- X
- Xreturns -1 or next user data row number to write
- X--------------------------------------------------------------------------*/
- XXLS_FILE *
- Xxls_append(filename)
- Xchar *filename;
- X{
- XbrDIMENSION dimension;
- Xint row;
- XXLS_FILE *x = (XLS_FILE *)malloc(sizeof(XLS_FILE));
- X
- X if(!x)
- X {
- X fprintf(stderr,"memory error\n");
- X return((XLS_FILE *)0);
- X }
- X
- X strcpy(x->filename,filename);
- X x->dimension_fpos = -1;
- X x->first_data_row = LABEL_ROW + 1;
- X x->last_data_row = -1;
- X
- X if(!(x->fp = fopen(filename,"r+")))
- X {
- X fprintf(stderr,"xls_append could not open '%s'\n",filename);
- X perror(filename);
- X return((XLS_FILE *)0);
- X }
- X
- X if((x->dimension_fpos = xls_get_brDIMENSION(x,&dimension)) < 0)
- X {
- X fprintf(stderr,"xls_append thinks '%s' is corrupt\n",filename);
- X perror(filename);
- X fclose(x->fp);
- X return((XLS_FILE *)0);
- X }
- X
- X if((row = dimension.rwMac - x->first_data_row) < 0)
- X {
- X fprintf(stderr,"xls_append unexpected next row in '%s'\n",filename);
- X perror(filename);
- X fclose(x->fp);
- X return((XLS_FILE *)0);
- X }
- X
- X if(fseek(x->fp,-4L,SEEK_END))
- X {
- X fprintf(stderr,"xls_append could not seek on '%s'\n",filename);
- X perror(filename);
- X fclose(x->fp);
- X return((XLS_FILE *)0);
- X }
- X
- X if(fgetc(x->fp) != btEOF)
- X {
- X fprintf(stderr,"xls_append found corrupt '%s'\n",filename);
- X perror(filename);
- X fclose(x->fp);
- X return((XLS_FILE *)0);
- X }
- X fseek(x->fp,-4L,SEEK_END);
- X
- X x->last_data_row = row;
- X return(x);
- X
- X} /* end of xls_append */
- X
- X/*+-------------------------------------------------------------------------
- X xls_create_Rlog(filename)
- X--------------------------------------------------------------------------*/
- XXLS_FILE *
- Xxls_create_Rlog(filename)
- Xchar *filename;
- X{
- Xint err;
- XbrBOF bof;
- XbrCOLWIDTH cw;
- XbrDIMENSION dim;
- XbrFONT *font;
- XbrFORMAT *fmt;
- XbrFORMATCOUNT fc;
- XbrLABEL *label;
- XbrNAME *name;
- Xchar *sHEADER_fmt =
- X "ECU Received File Log - created %02d-%02d-%04d %02d:%02d:%02d";
- Xchar *sDATE = "Date";
- Xchar *sFROM = "From";
- Xchar *sLENGTH = "Length";
- Xchar *sNAME = "Name";
- Xchar s80[80];
- Xtime_t now;
- Xstruct tm *lt;
- XXLS_FILE *x = (XLS_FILE *)malloc(sizeof(XLS_FILE));
- X
- X if(!x)
- X {
- X fprintf(stderr,"memory error\n");
- X return((XLS_FILE *)0);
- X }
- X
- X strcpy(x->filename,filename);
- X x->dimension_fpos = -1;
- X x->first_data_row = LABEL_ROW + 1;
- X x->last_data_row = -1;
- X
- X unlink(filename);
- X if(!(x->fp = fopen(filename,"w+")))
- X {
- X fprintf(stderr,"xls_create_Rlog could not open '%s'\n",filename);
- X perror(filename);
- X free((char *)x);
- X return((XLS_FILE *)0);
- X }
- X
- X chmod(filename,0644); /* only writable by owner */
- X
- X /* BOF */
- X bof.type = btBOF;
- X bof.length = sizeof(brBOF) - sizeof(BHDR);
- X bof.vers = versExcel;
- X bof.dt = dtWorksheet;
- X if(xls_write_br(x,(BHDR *)&bof) < 0)
- X goto ERROR_EXIT;
- X
- X /* HELV 10 font */
- X if(!(font = make_brFONT("Helv",200,0)))
- X goto ERROR_EXIT;
- X err = xls_write_br(x,(BHDR *)font) < 0;
- X free((char *)font);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* HELV 10 BOLD font */
- X if(!(font = make_brFONT("Helv",200,fBold)))
- X goto ERROR_EXIT;
- X err = xls_write_br(x,(BHDR *)font) < 0;
- X free((char *)font);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* column 0 width */
- X cw.type = btCOLWIDTH;
- X cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
- X cw.colFirst = Rlog_DATE_COL; /* 1st col in range */
- X cw.colLast = Rlog_DATE_COL; /* last col in range */
- X cw.dz = 3766; /* column width */
- X if(xls_write_br(x,(BHDR *)&cw) < 0)
- X goto ERROR_EXIT;
- X
- X /* column 1 width */
- X cw.type = btCOLWIDTH;
- X cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
- X cw.colFirst = Rlog_FROM_COL; /* 1st col in range */
- X cw.colLast = Rlog_FROM_COL; /* last col in range */
- X cw.dz = 3766; /* column width */
- X if(xls_write_br(x,(BHDR *)&cw) < 0)
- X goto ERROR_EXIT;
- X
- X /* column 2 width */
- X cw.type = btCOLWIDTH;
- X cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
- X cw.colFirst = Rlog_LENGTH_COL; /* 1st col in range */
- X cw.colLast = Rlog_LENGTH_COL; /* last col in range */
- X cw.dz = 2230; /* column width */
- X if(xls_write_br(x,(BHDR *)&cw) < 0)
- X goto ERROR_EXIT;
- X
- X /* column 3 width */
- X cw.type = btCOLWIDTH;
- X cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
- X cw.colFirst = Rlog_NAME_COL; /* 1st col in range */
- X cw.colLast = Rlog_NAME_COL; /* last col in range */
- X cw.dz = 8374; /* column width */
- X if(xls_write_br(x,(BHDR *)&cw) < 0)
- X goto ERROR_EXIT;
- X
- X /* FORMATCOUNT */
- X fc.type = btFORMATCOUNT;
- X fc.length = sizeof(brFORMATCOUNT) - sizeof(BHDR);
- X fc.FmtCount = FORMAT_COUNT;
- X if(xls_write_br(x,(BHDR *)&fc) < 0)
- X goto ERROR_EXIT;
- X
- X /* "General" FORMAT */
- X if(!(fmt = make_brFORMAT("General")))
- X goto ERROR_EXIT;
- X err = xls_write_br(x,(BHDR *)fmt) < 0;
- X free((char *)fmt);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* date FORMAT */
- X if(!(fmt = make_brFORMAT("yyyy-mm-dd hh:mm")))
- X goto ERROR_EXIT;
- X err = xls_write_br(x,(BHDR *)fmt) < 0;
- X free((char *)fmt);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* "DATE" NAME */
- X if(!(name = make_brNAME_area(sDATE,x->first_data_row,Rlog_DATE_COL,
- X TOTAL_DATA_ROWS,1)))
- X {
- X goto ERROR_EXIT;
- X }
- X err = xls_write_br(x,(BHDR *)name) < 0;
- X free((char *)name);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* "FROM" NAME */
- X if(!(name = make_brNAME_area(sFROM,x->first_data_row,Rlog_FROM_COL,
- X TOTAL_DATA_ROWS,1)))
- X {
- X goto ERROR_EXIT;
- X }
- X err = xls_write_br(x,(BHDR *)name) < 0;
- X free((char *)name);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* "LENGTH" NAME */
- X if(!(name = make_brNAME_area(sLENGTH,x->first_data_row,Rlog_LENGTH_COL,
- X TOTAL_DATA_ROWS,1)))
- X {
- X goto ERROR_EXIT;
- X }
- X err = xls_write_br(x,(BHDR *)name) < 0;
- X free((char *)name);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* "NAME" NAME */
- X if(!(name = make_brNAME_area(sNAME,x->first_data_row,Rlog_NAME_COL,
- X TOTAL_DATA_ROWS,1)))
- X {
- X goto ERROR_EXIT;
- X }
- X err = xls_write_br(x,(BHDR *)name) < 0;
- X free((char *)name);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* DIMENSION */
- X dim.type = btDIMENSION;
- X dim.length = sizeof(brDIMENSION) - sizeof(BHDR);
- X dim.rwMic = 0; /* first defined row */
- X dim.rwMac = x->first_data_row; /* last row + 1 */
- X dim.colMic = 0; /* first col */
- X dim.colMac = 4; /* last row + 1 */
- X if((x->dimension_fpos = xls_write_br(x,(BHDR *)&dim)) < 0)
- X goto ERROR_EXIT;
- X
- X /* HEADER */
- X time(&now);
- X lt = localtime(&now);
- X sprintf(s80,sHEADER_fmt,
- X lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
- X lt->tm_hour,lt->tm_min,lt->tm_sec);
- X if(!(label = make_brLABEL(s80)))
- X goto ERROR_EXIT;
- X label->rw = HEADER_ROW;
- X label->col = HEADER_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* DATE */
- X if(!(label = make_brLABEL(sDATE)))
- X goto ERROR_EXIT;
- X label->rw = LABEL_ROW;
- X label->col = Rlog_DATE_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X label->rgbAttr[2] = alc_LEFT;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* FROM */
- X if(!(label = make_brLABEL(sFROM)))
- X goto ERROR_EXIT;
- X label->rw = LABEL_ROW;
- X label->col = Rlog_FROM_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X label->rgbAttr[2] = alc_LEFT;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* LENGTH */
- X if(!(label = make_brLABEL(sLENGTH)))
- X goto ERROR_EXIT;
- X label->rw = LABEL_ROW;
- X label->col = Rlog_LENGTH_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X label->rgbAttr[2] = alc_LEFT;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* NAME */
- X if(!(label = make_brLABEL(sNAME)))
- X goto ERROR_EXIT;
- X label->rw = LABEL_ROW;
- X label->col = Rlog_NAME_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X label->rgbAttr[2] = alc_LEFT;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X return(x);
- X
- XERROR_EXIT:
- X fprintf(stderr,"xls_create_Rlog of '%s' aborted due to error\n",filename);
- X fclose(x->fp);
- X unlink(filename);
- X free((char *)x);
- X return((XLS_FILE *)0);
- X
- X} /* end of xls_create_Rlog */
- X
- X/*+-------------------------------------------------------------------------
- X xls_write_Rlog_record(x,row,date,from,length,name)
- X
- X returns file position of written record or -1 if error
- X--------------------------------------------------------------------------*/
- Xlong
- Xxls_write_Rlog_record(x,row,date,from,length,name)
- XXLS_FILE *x;
- Xint row;
- Xchar *date;
- Xchar *from;
- Xlong length;
- Xchar *name;
- X{
- XbrNUMBER num;
- XbrLABEL *label;
- Xlong fpos = ftell(x->fp);
- Xint err;
- X
- X /* DATE */
- X if(!(label = make_brLABEL(date)))
- X return(-1);
- X label->rw = x->first_data_row + row;
- X label->col = Rlog_DATE_COL;
- X label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X return(-1);
- X
- X /* FROM */
- X if(!(label = make_brLABEL(from)))
- X return(-1);
- X label->rw = x->first_data_row + row;
- X label->col = Rlog_FROM_COL;
- X label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X return(-1);
- X
- X /* LENGTH */
- X num.type = btNUMBER;
- X num.length = sizeof(brNUMBER) - sizeof(BHDR);
- X num.rw = x->first_data_row + row;
- X num.col = Rlog_LENGTH_COL;
- X num.num = (double)length;
- X num.rgbAttr[0] = rgbAttr0_fLocked;
- X num.rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
- X num.rgbAttr[2] = 0;
- X if(xls_write_br(x,(BHDR *)&num) < 0)
- X return(-1);
- X
- X /* NAME */
- X if(!(label = make_brLABEL(name)))
- X return(-1);
- X label->rw = x->first_data_row + row;
- X label->col = Rlog_NAME_COL;
- X label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X return(-1);
- X
- X x->last_data_row = row;
- X
- X return(fpos);
- X
- X} /* end of xls_write_Rlog_record */
- X
- X/*+-------------------------------------------------------------------------
- X xls_create_Clog(filename)
- X--------------------------------------------------------------------------*/
- XXLS_FILE *
- Xxls_create_Clog(filename)
- Xchar *filename;
- X{
- Xint err;
- XbrBOF bof;
- XbrCOLWIDTH cw;
- XbrDIMENSION dim;
- XbrFONT *font;
- XbrFORMAT *fmt;
- XbrFORMATCOUNT fc;
- XbrLABEL *label;
- XbrNAME *name;
- Xchar *sHEADER_fmt =
- X "ECU Connection Log - created %02d-%02d-%04d %02d:%02d:%02d";
- Xchar *sDATE = "Date";
- Xchar *sSYS = "System";
- Xchar *sPHONE = "Phone";
- Xchar *sTIME = "Time";
- Xchar s80[80];
- Xtime_t now;
- Xstruct tm *lt;
- XXLS_FILE *x = (XLS_FILE *)malloc(sizeof(XLS_FILE));
- X
- X if(!x)
- X {
- X fprintf(stderr,"memory error\n");
- X return((XLS_FILE *)0);
- X }
- X
- X strcpy(x->filename,filename);
- X x->dimension_fpos = -1;
- X x->first_data_row = LABEL_ROW + 1;
- X x->last_data_row = -1;
- X
- X unlink(filename);
- X if(!(x->fp = fopen(filename,"w+")))
- X {
- X fprintf(stderr,"xls_create_Clog could not open '%s'\n",filename);
- X perror(filename);
- X free((char *)x);
- X return((XLS_FILE *)0);
- X }
- X
- X chmod(filename,0644); /* only writable by owner */
- X
- X /* BOF */
- X bof.type = btBOF;
- X bof.length = sizeof(brBOF) - sizeof(BHDR);
- X bof.vers = versExcel;
- X bof.dt = dtWorksheet;
- X if(xls_write_br(x,(BHDR *)&bof) < 0)
- X goto ERROR_EXIT;
- X
- X /* HELV 10 font */
- X if(!(font = make_brFONT("Helv",200,0)))
- X goto ERROR_EXIT;
- X err = xls_write_br(x,(BHDR *)font) < 0;
- X free((char *)font);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* HELV 10 BOLD font */
- X if(!(font = make_brFONT("Helv",200,fBold)))
- X goto ERROR_EXIT;
- X err = xls_write_br(x,(BHDR *)font) < 0;
- X free((char *)font);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* column 0 width */
- X cw.type = btCOLWIDTH;
- X cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
- X cw.colFirst = Clog_DATE_COL; /* 1st col in range */
- X cw.colLast = Clog_DATE_COL; /* last col in range */
- X cw.dz = 3766; /* column width */
- X if(xls_write_br(x,(BHDR *)&cw) < 0)
- X goto ERROR_EXIT;
- X
- X /* column 1 width */
- X cw.type = btCOLWIDTH;
- X cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
- X cw.colFirst = Clog_SYS_COL; /* 1st col in range */
- X cw.colLast = Clog_SYS_COL; /* last col in range */
- X cw.dz = 3766; /* column width */
- X if(xls_write_br(x,(BHDR *)&cw) < 0)
- X goto ERROR_EXIT;
- X
- X /* column 2 width */
- X cw.type = btCOLWIDTH;
- X cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
- X cw.colFirst = Clog_PHONE_COL; /* 1st col in range */
- X cw.colLast = Clog_PHONE_COL; /* last col in range */
- X cw.dz = 3766; /* column width */
- X if(xls_write_br(x,(BHDR *)&cw) < 0)
- X goto ERROR_EXIT;
- X
- X /* column 3 width */
- X cw.type = btCOLWIDTH;
- X cw.length = sizeof(brCOLWIDTH) - sizeof(BHDR);
- X cw.colFirst = Clog_TIME_COL; /* 1st col in range */
- X cw.colLast = Clog_TIME_COL; /* last col in range */
- X cw.dz = 1974; /* column width */
- X if(xls_write_br(x,(BHDR *)&cw) < 0)
- X goto ERROR_EXIT;
- X
- X /* FORMATCOUNT */
- X fc.type = btFORMATCOUNT;
- X fc.length = sizeof(brFORMATCOUNT) - sizeof(BHDR);
- X fc.FmtCount = FORMAT_COUNT;
- X if(xls_write_br(x,(BHDR *)&fc) < 0)
- X goto ERROR_EXIT;
- X
- X /* "General" FORMAT */
- X if(!(fmt = make_brFORMAT("General")))
- X goto ERROR_EXIT;
- X err = xls_write_br(x,(BHDR *)fmt) < 0;
- X free((char *)fmt);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* time FORMAT */
- X if(!(fmt = make_brFORMAT("hh:mm:ss"))) /* Clog_FORMAT_TIME */
- X goto ERROR_EXIT;
- X err = xls_write_br(x,(BHDR *)fmt) < 0;
- X free((char *)fmt);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* "DATE" NAME */
- X if(!(name = make_brNAME_area(sDATE,x->first_data_row,Clog_DATE_COL,
- X TOTAL_DATA_ROWS,1)))
- X {
- X goto ERROR_EXIT;
- X }
- X err = xls_write_br(x,(BHDR *)name) < 0;
- X free((char *)name);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* "SYS" NAME */
- X if(!(name = make_brNAME_area(sSYS,x->first_data_row,Clog_SYS_COL,
- X TOTAL_DATA_ROWS,1)))
- X {
- X goto ERROR_EXIT;
- X }
- X err = xls_write_br(x,(BHDR *)name) < 0;
- X free((char *)name);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* "PHONE" NAME */
- X if(!(name = make_brNAME_area(sPHONE,x->first_data_row,Clog_PHONE_COL,
- X TOTAL_DATA_ROWS,1)))
- X {
- X goto ERROR_EXIT;
- X }
- X err = xls_write_br(x,(BHDR *)name) < 0;
- X free((char *)name);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* "TIME" NAME */
- X if(!(name = make_brNAME_area(sTIME,x->first_data_row,Clog_TIME_COL,
- X TOTAL_DATA_ROWS,1)))
- X {
- X goto ERROR_EXIT;
- X }
- X err = xls_write_br(x,(BHDR *)name) < 0;
- X free((char *)name);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* DIMENSION */
- X dim.type = btDIMENSION;
- X dim.length = sizeof(brDIMENSION) - sizeof(BHDR);
- X dim.rwMic = 0; /* first defined row */
- X dim.rwMac = x->first_data_row; /* last row + 1 */
- X dim.colMic = 0; /* first col */
- X dim.colMac = 4; /* last row + 1 */
- X if((x->dimension_fpos = xls_write_br(x,(BHDR *)&dim)) < 0)
- X goto ERROR_EXIT;
- X
- X /* HEADER */
- X time(&now);
- X lt = localtime(&now);
- X sprintf(s80,sHEADER_fmt,
- X lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
- X lt->tm_hour,lt->tm_min,lt->tm_sec);
- X if(!(label = make_brLABEL(s80)))
- X goto ERROR_EXIT;
- X label->rw = HEADER_ROW;
- X label->col = HEADER_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* DATE */
- X if(!(label = make_brLABEL(sDATE)))
- X goto ERROR_EXIT;
- X label->rw = LABEL_ROW;
- X label->col = Clog_DATE_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X label->rgbAttr[2] = alc_LEFT;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* SYS */
- X if(!(label = make_brLABEL(sSYS)))
- X goto ERROR_EXIT;
- X label->rw = LABEL_ROW;
- X label->col = Clog_SYS_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X label->rgbAttr[2] = alc_LEFT;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* PHONE */
- X if(!(label = make_brLABEL(sPHONE)))
- X goto ERROR_EXIT;
- X label->rw = LABEL_ROW;
- X label->col = Clog_PHONE_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X label->rgbAttr[2] = alc_LEFT;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X /* TIME */
- X if(!(label = make_brLABEL(sTIME)))
- X goto ERROR_EXIT;
- X label->rw = LABEL_ROW;
- X label->col = Clog_TIME_COL;
- X label->rgbAttr[1] = (FONT_HELV10_BOLD << 6) | FORMAT_GENERAL;
- X label->rgbAttr[2] = alc_LEFT;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X goto ERROR_EXIT;
- X
- X return(x);
- X
- XERROR_EXIT:
- X fprintf(stderr,"xls_create_Clog of '%s' aborted due to error\n",filename);
- X fclose(x->fp);
- X unlink(filename);
- X free((char *)x);
- X return((XLS_FILE *)0);
- X
- X} /* end of xls_create_Clog */
- X
- X/*+-------------------------------------------------------------------------
- X xls_write_Clog_record(x,row,date,sys,secs)
- X
- X returns file position of written record or -1 if error
- X--------------------------------------------------------------------------*/
- Xlong
- Xxls_write_Clog_record(x,row,date,sys,phone,secs)
- XXLS_FILE *x;
- Xint row;
- Xchar *date;
- Xchar *sys;
- Xchar *phone;
- Xlong secs;
- X{
- XbrNUMBER num;
- XbrLABEL *label;
- Xlong fpos = ftell(x->fp);
- Xint err;
- X
- X /* DATE */
- X if(!(label = make_brLABEL(date)))
- X return(-1);
- X label->rw = x->first_data_row + row;
- X label->col = Clog_DATE_COL;
- X label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X return(-1);
- X
- X /* SYS */
- X if(!(label = make_brLABEL(sys)))
- X return(-1);
- X label->rw = x->first_data_row + row;
- X label->col = Clog_SYS_COL;
- X label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X return(-1);
- X
- X /* PHONE */
- X if(!(label = make_brLABEL(phone)))
- X return(-1);
- X label->rw = x->first_data_row + row;
- X label->col = Clog_PHONE_COL;
- X label->rgbAttr[1] = (FONT_HELV10 << 6) | FORMAT_GENERAL;
- X err = xls_write_br(x,(BHDR *)label) < 0;
- X free((char *)label);
- X if(err)
- X return(-1);
- X
- X /* TIME */
- X num.type = btNUMBER;
- X num.length = sizeof(brNUMBER) - sizeof(BHDR);
- X num.rw = x->first_data_row + row;
- X num.col = Clog_TIME_COL;
- X num.num = (double)secs / (3600.0 * 24.0);
- X num.rgbAttr[0] = rgbAttr0_fLocked;
- X num.rgbAttr[1] = (FONT_HELV10 << 6) | Clog_FORMAT_TIME;
- X num.rgbAttr[2] = 0;
- X if(xls_write_br(x,(BHDR *)&num) < 0)
- X return(-1);
- X
- X x->last_data_row = row;
- X
- X return(fpos);
- X
- X} /* end of xls_write_Clog_record */
- X
- X/*+-------------------------------------------------------------------------
- X xls_write_eof_and_close(x)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xxls_write_eof_and_close(x)
- XXLS_FILE *x;
- X{
- XbrDIMENSION dimension;
- X
- X if(!x->fp)
- X {
- X fprintf(stderr,"xls_write_and_close: no file open!\n");
- X return;
- X }
- X
- X fputc(btEOF,x->fp);
- X fputc(0,x->fp);
- X fputc(0,x->fp);
- X fputc(0,x->fp);
- X
- X if(x->last_data_row >= 0)
- X {
- X if(x->dimension_fpos >= 0)
- X {
- X memset((char *)&dimension,0,sizeof(brDIMENSION));
- X errno = 0;
- X if(fseek(x->fp,x->dimension_fpos,SEEK_SET))
- X perror("xls_write_eof_and_close seek 1 error");
- X else if(fread((char *)&dimension,1,sizeof(brDIMENSION),x->fp) !=
- X sizeof(brDIMENSION))
- X {
- X perror("xls_write_eof_and_close dim read error");
- X }
- X dimension.rwMac = ++x->last_data_row +
- X x->first_data_row;
- X if(dimension.type == btDIMENSION)
- X {
- X if(fseek(x->fp,x->dimension_fpos,SEEK_SET))
- X perror("xls_write_eof_and_close seek 2 error");
- X else if(fwrite((char *)&dimension,1,
- X sizeof(brDIMENSION),x->fp) != sizeof(brDIMENSION))
- X {
- X perror("xls_write_eof_and_close dim write error");
- X }
- X }
- X else
- X fprintf(stderr,"xls_write_eof_and_close dim write fail\n");
- X }
- X else
- X fprintf(stderr,"xls_write_eof_and_close no dim fpos\n");
- X }
- X else
- X fprintf(stderr,"xls_write_eof_and_close no last row\n");
- X x->last_data_row = -1;
- X x->dimension_fpos = -1;
- X
- X fclose(x->fp);
- X x->fp = (FILE *)0;
- X
- X} /* end of xls_write_eof_and_close */
- X
- X/*+-------------------------------------------------------------------------
- X rearranged_date(date)
- X
- X0000000000111111
- X0123456789012345
- X12-28-1990-17:08
- X1990-12-28 17:08
- X--------------------------------------------------------------------------*/
- Xchar *
- Xrearranged_date(date)
- Xchar *date;
- X{
- Xstatic char rd[] = "####-##-## ##:##";
- X
- X memcpy(rd + 0,date + 6,4);
- X memcpy(rd + 5,date + 0,5);
- X memcpy(rd + 11,date + 11,5);
- X return(rd);
- X
- X} /* end of rearranged_date */
- X
- X/*+-------------------------------------------------------------------------
- X log_connect(logbuf)
- X
- X00000000001111111111222222222233
- X01234567890123456789012345678901
- X12-28-1990-17:06-01455-CONNECT tridom (426-0624) 9600 baud
- X--------------------------------------------------------------------------*/
- Xvoid
- Xlog_connect(logbuf)
- Xchar *logbuf;
- X{
- Xchar *sys = logbuf + 31;
- Xint pid = atoi(logbuf + 17);
- XCE *ce = ce_list_search(pid);
- Xchar *cptr;
- X
- X if(ce)
- X {
- X fprintf(stderr,"warning: connect to %s pid %d without disconnect\n",
- X ce->sys,pid);
- X ce_list_remove(ce);
- X free((char *)ce);
- X }
- X
- X if(!(ce = (CE *)malloc(sizeof(CE))))
- X {
- X fprintf(stderr,"memory allocation error\n");
- X exit(250);
- X }
- X
- X if(cptr = strchr(sys,' '))
- X *cptr = 0;
- X
- X strncpy(ce->sys,sys,sizeof(ce->sys));
- X ce->sys[sizeof(ce->sys) - 1] = 0;
- X strcpy(ce->date,rearranged_date(logbuf));
- X ce->pid = pid;
- X ce_list_add(ce);
- X
- X} /* end of log_connect */
- X
- X/*+-------------------------------------------------------------------------
- X log_disconnect(x,logbuf)
- X
- X00000000001111111111222222222233333
- X01234567890123456789012345678901234
- X12-28-1990-17:08-01455-DISCONNECT tridom (426-0624) 144 00:02:24
- X--------------------------------------------------------------------------*/
- Xlog_disconnect(x,logbuf)
- XXLS_FILE *x;
- Xchar *logbuf;
- X{
- Xchar *cptr;
- Xchar date[128];
- Xint pid = atoi(logbuf + 17);
- XCE *ce = ce_list_search(pid);
- Xchar *sys = logbuf + 34;
- Xlong secs = 0L;
- Xchar *phone = "";
- X
- X if(cptr = strchr(sys,' '))
- X {
- X *cptr = 0;
- X cptr += 2;
- X phone = cptr;
- X if(cptr = strrchr(phone,')'))
- X {
- X *cptr = 0;
- X cptr++;
- X secs = atol(cptr);
- X }
- X }
- X
- X if(ce)
- X {
- X strcpy(date,ce->date);
- X if(strcmp(ce->sys,sys))
- X {
- X fprintf(stderr,
- X "warning: system mismatch conn(%s) != disc(%s) pid %d\n",
- X ce->sys,sys,pid);
- X }
- X ce_list_remove(ce);
- X free((char *)ce);
- X }
- X else
- X strcpy(date,rearranged_date(logbuf));
- X
- X xls_write_Clog_record(x,++x->last_data_row,date,sys,phone,secs);
- X
- X} /* end of log_disconnect */
- X
- X/*+-------------------------------------------------------------------------
- X log_receive(x,logbuf)
- X
- X00000000001111111111222222222233333333334
- X01234567890123456789012345678901234567890
- X12-28-1990-17:08-01455-RECEIVE success: mbox (8016 bytes)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xlog_receive(x,logbuf)
- XXLS_FILE *x;
- Xchar *logbuf;
- X{
- Xchar *cptr;
- Xchar *date = rearranged_date(logbuf);
- Xint pid = atoi(logbuf + 17);
- XCE *ce = ce_list_search(pid);
- Xchar *from = (ce) ? ce->sys : "??";
- Xlong length = 0L;
- Xchar *name = logbuf + 40;
- X
- X if(cptr = strchr(name,' '))
- X {
- X *cptr = 0;
- X cptr += 2;
- X length = atol(cptr);
- X }
- X xls_write_Rlog_record(x,++x->last_data_row,date,from,length,name);
- X
- X} /* end of log_receive */
- X
- X/*+-------------------------------------------------------------------------
- X main(argc,argv)
- X
- X000000000011111111112222
- X012345678901234567890123
- X12-28-1990-17:06-01455-CONNECT tridom (426-0624) 9600 baud
- X12-28-1990-17:08-01455-RECEIVE success: mbox (8016 bytes)
- X12-28-1990-17:08-01455-DISCONNECT tridom (426-0624) 144 00:02:24
- X--------------------------------------------------------------------------*/
- Xmain(argc,argv)
- Xint argc;
- Xchar **argv;
- X{
- Xint itmp;
- Xint row;
- Xint errflg = 0;
- Xdouble Biffdate;
- Xdouble Avg;
- Xdouble Min;
- Xdouble Max;
- Xint Sampq;
- Xchar *fnRlog = "ecurlog.xls";
- XXLS_FILE *xRlog;
- Xchar *fnClog = "ecuclog.xls";
- XXLS_FILE *xClog;
- XFILE *fp_log;
- Xchar logname[256];
- Xchar logbuf[256];
- XCE *tce;
- Xextern char *optarg;
- Xextern int optind;
- X
- X logname[0] = 0;
- X
- X while((itmp = getopt(argc,argv,"l:")) != -1)
- X {
- X switch(itmp)
- X {
- X case 'l':
- X strcpy(logname,optarg);
- X break;
- X case '?':
- X errflg++;
- X break;
- X }
- X }
- X
- X if(errflg)
- X {
- X (void)fprintf(stderr,"usage: ecuxls [-l logfile]\n");
- X (void)fprintf(stderr,"default log file is ~/.ecu/log\n");
- X exit(254);
- X }
- X
- X if(!logname[0])
- X {
- X get_home_dir(logname);
- X strcat(logname,"/.ecu/log");
- X }
- X
- X fprintf(stderr,"ecuxls %s: %s -> (ecurlog.xls,ecuclog.xls)\n",
- X revision,logname);
- X
- X if(!(fp_log = fopen(logname,"r")))
- X {
- X perror(logname);
- X exit(1);
- X }
- X if(!(xRlog = xls_create_Rlog(fnRlog)))
- X {
- X perror(fnRlog);
- X exit(2);
- X }
- X if(!(xClog = xls_create_Clog(fnClog)))
- X {
- X perror(fnClog);
- X exit(2);
- X }
- X
- X while(fgets(logbuf,sizeof(logbuf),fp_log))
- X {
- X logbuf[strlen(logbuf) - 1] = 0;
- X if(!strncmp(logbuf + 23,"RECEIVE success",15))
- X log_receive(xRlog,logbuf);
- X else if(!strncmp(logbuf + 23,"CONNECT",7))
- X log_connect(logbuf);
- X else if(!strncmp(logbuf + 23,"DISCONNECT",10))
- X log_disconnect(xClog,logbuf);
- X }
- X
- X xls_write_eof_and_close(xRlog);
- X xls_write_eof_and_close(xClog);
- X fclose(fp_log);
- X
- X tce = ce_list_head;
- X while(tce)
- X {
- X fprintf(stderr,"warning: connect to %s pid %d without disconnect\n",
- X tce->sys,tce->pid);
- X tce = tce->next;
- X }
- X
- X exit(0);
- X} /* end of main */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- X/* end of ecuxls.c */
- SHAR_EOF
- chmod 0644 excel/ecuxls.c ||
- echo 'restore of excel/ecuxls.c failed'
- Wc_c="`wc -c < 'excel/ecuxls.c'`"
- test 37790 -eq "$Wc_c" ||
- echo 'excel/ecuxls.c: original size 37790, current size' "$Wc_c"
- fi
- # ============= excel/log ==============
- if test -f 'excel/log' -a X"$1" != X"-c"; then
- echo 'x - skipping excel/log (File already exists)'
- else
- echo 'x - extracting excel/log (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'excel/log' &&
- X01-09-1555-12123-04460-CONNECT tridom (555-1212) 9600 baud
- X01-09-1555-12126-04460-DISCONNECT tridom (555-1212) 7327 02:02:07
- X01-09-1555-12125-05555-CONNECT n4vu (555-1212V) 9600 baud
- X01-09-1555-12128-05555-DISCONNECT n4vu (555-1212V) 187 00:03:07
- X01-09-1555-12121-05588-CONNECT n4vu (555-1212V) 9600 baud
- X01-09-1555-12123-05588-DISCONNECT n4vu (555-1212V) 113 00:01:53
- X01-09-1555-12121-05838-CONNECT p1so (555-1212PF) 9600 baud
- X01-09-1555-12121-05838-DISCONNECT p1so (555-1212PF) 23 00:00:23
- X01-09-1555-12122-05838-CONNECT kd4nc (555-1212C) 19200 baud
- X01-09-1555-12126-05838-RECEIVE success: afterlint.c (4060 bytes)
- X01-09-1555-12126-05838-RECEIVE success: ecu.c (9889 bytes)
- X01-09-1555-12126-05838-RECEIVE success: ecu.h (4175 bytes)
- X01-09-1555-12126-05838-RECEIVE success: ecuicmd.c (12787 bytes)
- X01-09-1555-12127-05838-RECEIVE success: eculine.c (23999 bytes)
- X01-09-1555-12128-05838-RECEIVE success: ecuphone.c (48334 bytes)
- X01-09-1555-12128-05838-RECEIVE success: ecurcvr.c (31419 bytes)
- X01-09-1555-12128-05838-RECEIVE success: ecushm.h (3040 bytes)
- X01-09-1555-12129-05838-RECEIVE success: ecuvmin.h (585 bytes)
- X01-09-1555-12129-05838-RECEIVE success: ecuxenix.c (14172 bytes)
- X01-09-1555-12129-05838-RECEIVE success: gint.c (6599 bytes)
- X01-09-1555-12120-05838-RECEIVE success: lint_args.h (27013 bytes)
- X01-09-1555-12120-05838-RECEIVE success: pcmd.c (24245 bytes)
- X01-09-1555-12120-05838-RECEIVE success: pprintf.c (3525 bytes)
- X01-09-1555-12121-05838-RECEIVE success: stdio_lint.h (1286 bytes)
- X01-09-1555-12122-05838-DISCONNECT kd4nc (555-1212C) 7238 02:00:38
- SHAR_EOF
- chmod 0644 excel/log ||
- echo 'restore of excel/log failed'
- Wc_c="`wc -c < 'excel/log'`"
- test 1563 -eq "$Wc_c" ||
- echo 'excel/log: original size 1563, current size' "$Wc_c"
- fi
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-